package com.hnxxxy.workshop.controller;


import com.hnxxxy.workshop.request.DepotPageRequest;
import com.hnxxxy.workshop.request.DepotRequest;
import com.hnxxxy.workshop.request.FactoryPageRequest;
import com.hnxxxy.workshop.request.FactoryRequest;
import com.hnxxxy.workshop.service.DepotService;
import com.hnxxxy.workshop.utils.R;
import com.hnxxxy.workshop.vo.DepotVO;
import com.hnxxxy.workshop.vo.FactoryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>
 * 仓库 前端控制器
 * </p>
 *
 * @author zqh
 * @since 2022-05-09
 */
@RestController
@RequestMapping("/depot")
@Api(value = "DepotController", tags = {"仓库模块"})
public class DepotController {

    @Resource
    private DepotService depotService;

    @PostMapping("/add")
    @ApiOperation(value = "创建仓库")
    public R add(@ApiParam("仓库对象") @RequestBody DepotRequest depotRequest){
        depotService.add(depotRequest);
        return R.buildSuccess();
    }

    @GetMapping("/remove/{id}")
    @ApiOperation(value = "删除仓库")
    public R deleteById(@ApiParam(value = "仓库id",required = true)
                        @PathVariable("id") int id){
        depotService.deleteById(id);
        return R.buildSuccess();
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改仓库")
    public R update( @ApiParam("仓库对象")
                     @RequestBody DepotRequest depotRequest){
        depotService.update(depotRequest);
        return R.buildSuccess();
    }

    @GetMapping("/findById/{id}")
    @ApiOperation(value = "根据id查询仓库信息")
    public R findByIdDepot(@ApiParam(value = "仓库id",required = true)
                             @PathVariable("id") int id ){
        DepotVO depotVO = depotService.findByIdDepot(id);
        return R.buildSuccess(depotVO);
    }

    @PostMapping("/page")
    @ApiOperation(value = "分页查询全部仓库")
    public R findByIdFactory(@ApiParam(value = "分页对象",required = true)
                             @RequestBody DepotPageRequest depotPageRequest){
        Map<String,Object> pageResult = depotService.page(depotPageRequest);
        return R.buildSuccess(pageResult);
    }
}

